package ass.web;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ass.beans.UserFriendsBean;
import ass.dao.UserFriendsDAO;
import ass.dao.support.UserFriendsDAOImpl;

/**
 * Servlet implementation class updateFrdRqst
 */
public class updateFrdRqst extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public updateFrdRqst() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		UserFriendsDAO userFriendsDAO = new UserFriendsDAOImpl();
		String username = (String) request.getParameter("username");
		String usernameFriend = (String) request.getParameter("usernameFriend");
		String status = (String) request.getParameter("status");
		
		UserFriendsBean userFriendsBean = new UserFriendsBean();
		userFriendsBean.setUsername(username);
		userFriendsBean.setUsernameFriend(usernameFriend);	
		
		if (status.equals("accept")) {
			userFriendsDAO.update(userFriendsBean, true);
		}else if (status.equals("reject")){
			userFriendsDAO.update(userFriendsBean, false);
		}
		
		request.setAttribute("updated", "<font color='green'> Friend acceptance status updated </font>");
		String nextJSP = "";
		nextJSP = "/ViewFrdRqst";
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
		dispatcher.forward(request, response);

	}

}
